-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(rust): make 100 * pl.col(pl.Boolean).mean() work #13725
Conversation
@@ -127,7 +127,11 @@ impl AExpr { | |||
Mean(expr) => { | |||
let mut field = | |||
arena.get(*expr).to_field(schema, Context::Default, arena)?; | |||
float_type(&mut field); | |||
if matches!(&field.dtype, DataType::Boolean) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This branch already happens in the float_type
call?
Edit. I see that there are two float_type
functions that are inconsistent. Boolean
should be added to the float_type
function, not as an exclusion here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll be honest, I just blindly copied @advoet's code from the linked issue. But it does fix the bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does fix it, but it is a bandaid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to implement a more robust fix, just let me know where the "right" place to change would be. It's an important fix because people like to use 100 * boolean_column.mean() to calculate percentages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a lot of cases where boolean is treated as a u8
in these types of operations. It might be worth adding is_numeric_or_bool()
for those many cases scattered throughout the codebase (perhaps different PR).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eh, I just perused through and it feels like it's not worth it. Go ahead with this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just not familiar enough with the Rust codebase to know what a non-bandaid fix would look like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
He just means at the very top of the file do this instead of your else
clause below:
fn float_type(field: &mut Field) {
if (field.dtype.is_numeric() || field.dtype == DataType::Boolean)
&& field.dtype != DataType::Float32
{
field.coerce(DataType::Float64)
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohhh I didn't see Ritchie's edit to his original post! thanks :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
He may have been noting the other float_type
function in expr_dyn_fn.rs
but this is actually never used.
@ritchie46 updated this PR based on your suggestion:
|
Co-authored-by: Wainberg <m.wainberg@utoronto.ca>
Closes #7651 based on the implementation suggested by @advoet here.
Before:
After: